import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Ordering;
import com.google.common.collect.ImmutableSortedMap.Builder;

    //resp.setHeader(CACHE_CONTROL, "no-store, no-cache, must-revalidate");
    //resp.setHeader(CACHE_CONTROL, "private, max-age=0");
    //resp.setHeader(CACHE_CONTROL, "public, must-revalidate, proxy-revalidate, max-age=0");
   

    //
    // calculate the Id for the page
    //
    
    final Builder<String, String> parametersLB = 
      new ImmutableSortedMap.Builder<String, String>(Ordering.natural()); 
    
    // each time when CachedPage class been changed we will automatically 
    // get another PageCacheId, so we avoid deserialization errors
    parametersLB.put(CachedPage.autoSerialVersionUID.toString(), uri);
    
    // TODO add sorted parameters to parametersList 
      
    // TODO add sorted cookies to parametersList
    
    final String pageCacheId = join("\\", parametersList);
    

    CachedPage cachedPage = null; //(CachedPage) cache.get(pageCacheId);
    
    // check validity
    /*
    if (cachedPage != null) {
      final Map<String, String> dependentResources = (Map) 
        cache.getAll((Set) cachedPage.dependentResources.keySet());
      MapDifference<String, String> diff = 
        Maps.difference(cachedPage.dependentResources, dependentResources);
      
      // if some dependent resources missed in memcached we will recalculate it
      if (!diff.entriesOnlyOnLeft().isEmpty()) {
        
        // TODO dependentResources.put(key, value);
        
        diff = Maps.difference(cachedPage.dependentResources, dependentResources);
      }
      
      if (!diff.areEqual())
        cachedPage = null;
    }*/
    
    if (cachedPage == null) {
      // regenerate
->
      cachedPage = new CachedPage(content, contentType,
        // TODO list of dependencies
        Collections.EMPTY_MAP);
      /*
      cache.put(pageCacheId, cachedPage);
      */
    }

    //req.getSession().getServletContext().
    /*final RequestDispatcher dispatcher =
      getServletContext().getRequestDispatcher("/index.xml");
    final ServletResponse dataResponce = new HttpServletResponseCatcher(resp);
    dispatcher.include(req, dataResponce);
    //dataResponce.getWriter().toString();
    final String a = dataResponce.getOutputStream().toString();*/

  /*@Override
  public long getLastModified(final HttpServletRequest req) 
  {
    return ((CachedPage) req.getAttribute(CACHED_PAGE)).lastModified.getTime();
  }*/
  
  // get real file name
  public static String getFileName(final HttpServletRequest req)
  {
    final String uri = req.getRequestURI();
    final String fileName = (uri.startsWith("/xslt/") ? "WEB-INF" : "data") + uri; 
    return new File(fileName).toURI().toString();
  }
  
